import type { Equal, Expect } from "@type-challenges/utils";

type cases = [
  Expect<Equal<Concat<[], []>, []>>,
  Expect<Equal<Concat<[], [1]>, [1]>>,
  Expect<Equal<Concat<[1, 2], [3, 4]>, [1, 2, 3, 4]>>,
  Expect<
    Equal<
      Concat<["1", 2, "3"], [false, boolean, "4"]>,
      ["1", 2, "3", false, boolean, "4"]
    >
  >
];

// infer 和 spread 运用
// 两道题
// 1. 取数组第一个元素类型 和
// 2. 取数组最后一个元素类型
// first [1,2,3] => 1
// tail [1,2,3] => 3
type FirstType<T extends any[]> = T extends [infer X, ...infer R] ? X : never;
type TailType<T extends any[]> = T extends [...infer X, infer R] ? R : never;
type T1 = FirstType<["1", "2"]>;
type Testcases = [
  Expect<Equal<FirstType<["1", "2", "3"]>, "1">>,
  Expect<Equal<FirstType<[true, "2", "3"]>, true>>,
  Expect<Equal<TailType<[true, "2", "3"]>, "3">>
];
